/**
 * 
 */
package org.rico.schema;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.xml.AbstractSingleBeanDefinitionParser;
import org.w3c.dom.Element;

/**
 * @author rico
 *
 */
public class CustomSchemaBeanDefinitionParser extends AbstractSingleBeanDefinitionParser {
	
	protected Class<?> getBeanClass(Element element) {
		return CustomSchema.class;
	}
	
	protected void doParse(Element element, BeanDefinitionBuilder builder) {
		String name = element.getAttribute("name");
		String value = element.getAttribute("value");
		Integer order = StringUtils.isNotBlank(element.getAttribute("order"))?Integer.valueOf(element.getAttribute("order")):0;

		if(StringUtils.isNotBlank(name)) {
			builder.addPropertyValue("name", name);
		}
		if(StringUtils.isNotBlank(value)) {
			builder.addPropertyValue("value", value);
		}
		if(order != null) {
			builder.addPropertyValue("order", order);
		}
		
	}
	
}
